import thread.Bank;

public class SyncDemo1 {
    private static boolean success1 = false;
    private static boolean success2 = false;

    public static void main(String[] args) {
        Bank bank = new Bank();
        int num = 1;
        while (true) {
            Thread t1 = new Thread(() -> success1 = bank.getMoney(20000));
            Thread t2 = new Thread(() -> success2 = bank.getMoney(20000));
            t1.start();
            t2.start();
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (success1 && success2) {
                System.out.println("测试了:"+num+"次");
                System.out.println("全部取款成功，发现并发安全问题");
                break;
            } else {
                num++;
                bank.saveMoney(20000);
                success1 = false;
                success2 = false;
            }
        }
    }
}
